//
//  UIScrollView+empty.m
//  LNTS
//
//  Created by oceans on 2019/5/28.
//  Copyright © 2019 oceans. All rights reserved.
//

#import "UIScrollView+empty.h"
#import <objc/runtime.h>

@implementation UIScrollView (empty)

- (UIView *)emptyView {
    
    static id emptyView = nil;
    return objc_getAssociatedObject(self, @selector(emptyView))?:emptyView;
}

- (void)setEmptyView:(UIView *)emptyView {
    objc_setAssociatedObject(self, @selector(emptyView), emptyView, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

- (void)showEmpty {
    
    if (self.emptyView == nil) {
        self.emptyView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height)];
        self.emptyView.backgroundColor = [UIColor whiteColor];
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenWidth*0.5-75, 100, 150, 150)];
        imageView.image = [UIImage imageNamed:@"image_336"];
        [self.emptyView addSubview:imageView];
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 260, ScreenWidth, 30.0)];
        label.font = [UIFont systemFontOfSize:16.0];
        label.textAlignment = NSTextAlignmentCenter;
        label.textColor = COLOR(153, 153, 153, 1);
        label.text = @"请输入要搜索的关键字，支持模糊查询。";
        [self.emptyView addSubview:label];
        [self addSubview:self.emptyView];
    }
    self.emptyView.hidden = NO;
}

- (void)hideEmpty {
    self.emptyView.hidden = YES;
}

@end
